package com.xiaoxin.yixinai.role;

import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.xiaoxin.yixinai._frame.base.BaseRepository;


@Repository
public interface RoleDao extends BaseRepository<RoleInfo> {
    @Query(value = "select * from tb_role_info where role_code = :roleCode and company_id = :companyId and is_delete = 0 limit 1",nativeQuery = true)
    RoleInfo findByRoleCodeAndCompanyId(@Param("roleCode") String roleCode, @Param("companyId") Integer companyId);

    @Query(nativeQuery = true,value = "select count(1) from tb_role_info role_name=:roleName and isDelete=0")
    int isExistRoleName(@Param("roleName") String roleName);

    @Query(nativeQuery = true,value = "select count(1) from tb_role_info role_code=:roleCode and isDelete=0")
    int isExistRoleCode(@Param("roleCode") String roleCode);

    @Query("from RoleInfo where roleId in (select roleId from RoleUser where userId = :userId and type = :type) ")
    List<RoleInfo> findRolesByUserId(@Param("userId") int userId,@Param("type") int type);

    @Query("from RoleInfo where isDelete=0 order by orderIndex asc")
    List<RoleInfo> getRoleList();
    
}
